//
//  TFNetWorkCell.swift
//  TalkfunSDKDemo
//
//  Created by 邓盛明 on 2022/3/10.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TFNetWorkCell: UITableViewCell {

    @objc public var bgView:UIView!
    @objc public var titleLab:UILabel!
    @objc public var tf_width:CGFloat = 0
    @objc public var model:TFNetWorkModel?
    {
        didSet{
            if(model != nil)
            {
                self.setModelUI(model: model!)
            }
        }
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.bgView = UIView.init()
        self.bgView.layer.masksToBounds = true
        
        self.bgView.layer.cornerRadius = 4;
        self.contentView.addSubview(self.bgView)
      
        
        self.titleLab = UILabel.init()
        
        self.titleLab.textColor = UIColor(red: 5/255.0, green: 211/255.0, blue: 128/255.0, alpha: 1.0)
        self.titleLab.font = UIFont.PingFang(size: 16)
        self.titleLab.textAlignment = .center;
        self.bgView.addSubview(self.titleLab)
      
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.bgView.frame = CGRect(x: 21, y: 0, width: self.tf_width-42, height: 40)
        self.titleLab.frame = CGRect(x: 0, y: 0, width: self.bgView.frame.size.width, height: 40)
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setModelUI( model:TFNetWorkModel) {
        if (model.isSelect) {
            self.bgView.backgroundColor = UIColor.white
            self.bgView.layer.borderWidth = 1.0;
            self.bgView.layer.borderColor = UIColor(red: 65/255.0, green: 150/255.0, blue: 235/255.0, alpha: 1.0).cgColor
            self.titleLab.textColor = UIColor(red: 65/255.0, green: 150/255.0, blue: 235/255.0, alpha: 1.0)
        } else {
            self.bgView.backgroundColor = UIColor.clear
            self.bgView.layer.borderWidth = 1.0;
            self.bgView.layer.borderColor = UIColor(red: 201/255.0, green: 211/255.0, blue: 221/255.0, alpha: 0.5).cgColor
    
            self.titleLab.textColor = UIColor(red: 20/255.0, green:23/255.0, blue: 26/255.0, alpha: 0.5)
      
        }
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
